package com.weijian.config;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * 社交功能Redis配置
 * 配置RedisTemplate和StringRedisTemplate用于社交功能
 */
@Configuration
public class SocialRedisConfig {
    /**
     * Redis key前缀定义
     */
    public static class RedisKeys {
        // 用户关注相关
        public static final String USER_FOLLOWING = "social:user:following:";
        public static final String USER_FOLLOWERS = "social:user:followers:";
        public static final String USER_FOLLOWING_COUNT = "social:user:following:count:";
        public static final String USER_FOLLOWERS_COUNT = "social:user:followers:count:";
        
        // 共同好友相关
        public static final String USER_MUTUAL_FRIENDS = "social:user:mutual:";
        
        // 课程点赞相关
        public static final String COURSE_LIKED_USERS = "social:course:liked:users:";
        public static final String USER_LIKED_COURSES = "social:user:liked:courses:";
        public static final String COURSE_LIKE_COUNT = "social:course:like:count:";
        public static final String USER_LIKE_COUNT = "social:user:like:count:";
        
        // 排行榜相关
        public static final String FOLLOWING_LEADERBOARD = "social:leaderboard:following";
        public static final String LIKES_LEADERBOARD = "social:leaderboard:likes";
        
        // 临时缓存
        public static final String TEMP_CACHE = "social:temp:";
    }

    /**
     * Redis过期时间定义（秒）
     */
    public static class RedisExpire {
        // 关注关系缓存（7天）
        public static final long FOLLOW_RELATION = 7 * 24 * 3600L;
        
        // 计数器缓存（1小时）
        public static final long COUNTER = 3600L;
        
        // 排行榜缓存（30分钟）
        public static final long LEADERBOARD = 1800L;
        
        // 临时数据缓存（5分钟）
        public static final long TEMP_DATA = 300L;
        
        // 用户会话缓存（24小时）
        public static final long USER_SESSION = 24 * 3600L;
    }
}